﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BoardPACDSDAO.Entity;
using BoardPACUtil.Util;

namespace BoardPACDSDAO.UserMgt
{
    public class UserDAO
    {
        public string GetUserDisplayName(string userName)
        {
            try
            {
                using (BoardAppProductEntities context = DataObjectFactory.CreateContext())
                {
                    var displayName = (from u in context.Users
                                       where u.UserName.Equals(userName)
                                       select u.FirstName + " " + u.LastName).FirstOrDefault();

                    return displayName;
                }
            }
            catch (GenServiceException)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public int GetUserCustomIdDAO(string userName)
        {
            try
            {
                using (BoardAppProductEntities ntb = DataObjectFactory.CreateContext())
                {
                    return (from u in ntb.Users where u.UserName == userName select u.CustomUserId).FirstOrDefault();
                }
            }
            catch (GenServiceException)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
